<?php

function current_link_index($link, $links, $span=false) {
	$html = '';
	$span = $span ? '<span></span>' : '';
	foreach($links AS $l=>$n) {
		if (trim($l,'/')==trim($link,'/')) {
			$html .= "<li class=\"current\"><a href=\"{$l}\"><span>{$n}</span></a>{$span}</li>";
		}
		else $html .= "<li><a href=\"{$l}\"><span>{$n}</span></a>{$span}</li>";
	}
	return $html;
}

function current_backend() {
	global $INI;
	global $login_user;
	if($login_user['proxy_auth'] == 1 && $login_user['proxy'] == 'Y'){
	    $a = array(
			'/manage/misc/index.php' => '首页',
			'/manage/team/index.php' => '项目',
			'/manage/order/index.php' => '订单',
			'/manage/coupon/index.php' => $INI['system']['couponname'],
			'/manage/yimamms/index.php' => '二维码',
			'/manage/partner/index.php' => '商户',
			'/manage/user/manager.php' => '角色',
			
			//'/manage/system/index.php' => '设置',
			);
	}else {
	    $a = array(
			'/manage/misc/index.php' => '首页',
			'/manage/team/index.php' => '项目',
			'/manage/order/index.php' => '订单',
			'/manage/coupon/index.php' => $INI['system']['couponname'],
			'/manage/yimamms/index.php' => '二维码',
			'/manage/partner/index.php' => '商户',
			
			//'/manage/system/index.php' => '设置',
			);
	}
	
	$r = $_SERVER['REQUEST_URI'];
	if (preg_match('#/manage/(\w+)/#',$r, $m)) {
		$l = "/manage/{$m[1]}/index.php";
	} else $l = '/manage/misc/index.php';
	return current_link($l, $a);
}

function current_city($cename, $citys) {
	$link = "/city.php?ename={$cename}";
	$links = array();
	foreach($citys AS $city) {
		$links["/city.php?ename={$city['ename']}"] = $city['name'];
	}
	return current_link($link, $links);
}


function current_about($selector='us') {
	global $INI;
	$a = array(
		'/about/us.php' => '关于' . $INI['system']['abbreviation'],
		'/about/contact.php' => '联系方式',
		'/about/job.php' => '工作机会',
		'/about/terms.php' => '用户协议',
		'/about/privacy.php' => '隐私声明',
	);
	$l = "/about/{$selector}.php";
	return current_link($l, $a, true);
}

function current_help($selector='faqs') {
	global $INI;
	$a = array(
		'/help/tour.php' => '玩转' . $INI['system']['abbreviation'],
		'/help/faqs.php' => '常见问题',
		'/help/zuitu.php' => $INI['system']['abbreviation'] . '是什么',
	    '/help/widget.php' => '团购挂件',
    );
    $b = array(
		'/help/tour.php' => '玩转' . $INI['system']['abbreviation'],
		'/help/faqs.php' => '常见问题',
		'/help/zuitu.php' => $INI['system']['abbreviation'] . '是什么',
	);
    $a = option_yes('widget') ? $a : $b;
	$l = "/help/{$selector}.php";
	return current_link($l, $a, true);
}


function current_link($link, $links, $span=false) {
	$html = '';
	$span = $span ? '<span></span>' : '';
	foreach($links AS $l=>$n) {
		if (trim($l,'/')==trim($link,'/')) {
			$html .= "<li class=\"current\"><a href=\"{$l}\">{$n}</a>{$span}</li>";
		}
		else $html .= "<li><a href=\"{$l}\">{$n}</a>{$span}</li>";
	}
	return $html;
}

/* manage current */
function mcurrent_misc($selector=null) {
	$a = array(
		'/manage/misc/index.php' => '首页',
	);
	$l = "/manage/misc/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_order($selector=null) {
	$a = array(
		'/manage/order/index.php' => '当期订单',
		'/manage/order/pay.php' => '付款订单',
		'/manage/order/credit.php' => '余额支付',
		'/manage/order/unpay.php' => '未付订单',
        '/manage/order/refund.php' => '退款管理',
		'/manage/order/express.php' => '上传快递单号',
	);
	$l = "/manage/order/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_user($selector=null) {
    global $login_user;
    if($login_user['proxy_auth'] == 1 && $login_user['proxy'] == 'Y'){
       $a = array(
    		//'/manage/user/index.php' => '用户列表',
    		'/manage/user/manager.php' => '员工列表',
    		'/manage/user/create.php' => '新建员工',
    	); 
    }
	$l = "/manage/user/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_team($selector=null) {
	$a = array(
		'/manage/team/index.php' => '当前项目',
		'/manage/team/success.php' => '成功项目',
		'/manage/team/failure.php' => '失败项目',
		'/manage/team/auditing.php' => '审核中的项目',
		'/manage/team/passed.php' => '审核未通过项目',
		'/manage/team/edit.php' => '新建项目',
	);
	$l = "/manage/team/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_coupon($selector=null) {
	$a = array(
		'/manage/coupon/index.php' => '未消费',
		'/manage/coupon/consume.php' => '已消费',
		'/manage/coupon/expire.php' => '已过期',
	);
	$l = "/manage/coupon/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_yimamms($selector=null) {
	$a = array(
		'/manage/yimamms/index.php' => '未消费',
		'/manage/yimamms/consume.php' => '已使用',
		'/manage/yimamms/expire.php' => '已过期',
		'/manage/yimamms/cancel.php' => '已撤销',
	);
	$l = "/manage/yimamms/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_partner($selector=null) {
	$a = array(
		'/manage/partner/index.php' => '商户列表',
		'/manage/partner/create.php' => '新建商户',
	);
	$l = "/manage/partner/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_system($selector=null) {
	$a = array(
		'/manage/system/index.php' => '基本',
		'/manage/system/option.php' => '选项',
		'/manage/system/bulletin.php' => '公告',
		'/manage/system/pay.php' => '支付',
		'/manage/system/email.php' => '邮件',
		'/manage/system/sms.php' => '短信',
		'/manage/system/page.php' => '页面',
		'/manage/system/cache.php' => '缓存',
		'/manage/system/skin.php' => '皮肤',
		'/manage/system/template.php' => '模板',
		'/manage/system/upgrade.php' => '升级',
	);
	$l = "/manage/system/{$selector}.php";
	return current_link($l,$a,true);
}
